package org.dtrd.modules.system.entity.bean.weixin;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.dtrd.config.wechat.config.WechatConstant;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author qr
 * @date 2022/3/28 13:30
 */
@ApiModel
@Getter
@Setter
@NoArgsConstructor
@XmlRootElement(name = "xml")
public class WxPassiveResp {

    @ApiModelProperty("接收方帐号（收到的OpenID）")
    private String toUserName;

    @ApiModelProperty("开发者微信号")
    private String fromUserName;

    @ApiModelProperty("消息创建时间 （整型）")
    private Long createTime;

    @ApiModelProperty("消息类型，文本为text")
    private String msgType;

    @ApiModelProperty("回复的消息内容（换行：在content中能够换行，微信客户端就支持换行显示）")
    private String content;

    public WxPassiveResp(WxEventPushBean wxEventPush) {
        // 注意这里的 from 和 to 的顺序!!!
        this.toUserName = wxEventPush.getFromUserName();
        this.fromUserName = wxEventPush.getToUserName();
        this.createTime = System.currentTimeMillis();
    }

    public WxPassiveResp buildText(WechatConstant.MsgType type, String content) {
        this.msgType = type.name();
        this.content = content;
        return this;
    }

    @XmlElement(name = "ToUserName")
    public String getToUserName() {
        return toUserName;
    }

    @XmlElement(name = "FromUserName")
    public String getFromUserName() {
        return fromUserName;
    }

    @XmlElement(name = "CreateTime")
    public Long getCreateTime() {
        return createTime;
    }

    @XmlElement(name = "MsgType")
    public String getMsgType() {
        return msgType;
    }

    @XmlElement(name = "Content")
    public String getContent() {
        return content;
    }
}
